package edu.scnu.fans.fingertip.item.controller;

import edu.scnu.fans.fingertip.common.api.ApiResponse;
import edu.scnu.fans.fingertip.common.api.IdRequest;
import edu.scnu.fans.fingertip.common.api.ResponseUtils;
import edu.scnu.fans.fingertip.common.api.RowResponse;
import edu.scnu.fans.fingertip.item.api.ItemApi;
import edu.scnu.fans.fingertip.item.item.ItemService;
import edu.scnu.fans.fingertip.item.output.ItemOutput;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "商品相关API")
public class ItemController implements ItemApi {

    @Resource
    private ItemService itemService;

    @ApiOperation("商品列表")
    @PostMapping("/fingertip/item/v1/list")
    public RowResponse<List<ItemOutput>> list() {
        List<ItemOutput> list = itemService.list();
        return ResponseUtils.rows(list);
    }

    @Override
    @ApiOperation("商品详情")
    @PostMapping("/fingertip/item/v1/detail")
    public ApiResponse<ItemOutput> detail(@RequestBody @Valid IdRequest input) {
        ItemOutput output = itemService.detail(input);
        return new ApiResponse<>(output);
    }
}
